package com.work.example.demo5.controller;

import com.work.example.demo5.domain.BorrowEntity;
import com.work.example.demo5.domain.vo.BorrowEntityVo;
import com.work.example.demo5.domain.vo.BorrowformVo;
import com.work.example.demo5.service.BorrowService;
import com.work.example.demo5.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/borrow")
public class BorrowController {
    @Autowired
    private  BorrowService borrowService;
    @GetMapping("/list")
    public R list(@RequestParam("username") String username ) {
        System.out.println(username);
        return R.success(borrowService.getByName(username));
    }
    @GetMapping("/getallborrow")
    public R getallborrow() {
        return R.success(borrowService.getallborrow());
    }
    @PostMapping("/addborrow")
    public R addborrow(@RequestBody BorrowformVo BorrowformVo){
        System.out.println(BorrowformVo);
        return R.success(borrowService.saveBorrow(BorrowformVo));
    }
    @GetMapping("/deleteborrow")
    public R deleteborrow(@RequestParam("id") Long id){
        System.out.println(id);
        return R.success(borrowService.deletebyId(id));
    }
    @PostMapping("/updateborrow")
    public R updateborrow(@RequestBody BorrowEntityVo borrowEntityVo){
        return R.success(borrowService.updateborrow(borrowEntityVo));
    }
}
